﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Business.IManager;
using Utility;
using Entity;
using DataAccess.IService;
using DataAccess.Service;
using System.Data;

namespace Business.Manager
{
    public class AccountManager:IAccountManager
    {

        IAccountService accountService = new AccountService();
        //5个
        public Student getStudent(String stuId)
        {
            return accountService.getStudentInform(stuId);
        }
        public bool changePwd(Student student, String newPassword)
        {
            if (student.Password != newPassword)
            {

                accountService.updatePassword(student.StudentId, newPassword);
                return true;
            }
            else
            {
                return false;
            }
        }
        public Student logIn(Student student)
        {
            Student fromDB = accountService.exist(student.StudentId, student.Password);
            if (fromDB.Password==null)
            {
                return null;
            }
            if (fromDB.StudentId.Equals(student.StudentId)&&fromDB.Password.Equals(student.Password))
            {
                return fromDB;
            }
            else
            {
                return null;
            }
        }

        public String checkStuId(String idCardNum)
        {
            Student stu = accountService.getStudentByIdCardNum(idCardNum);
            return stu.StudentId;
        }

        public bool checkStuPassword(Student student)
        {
            if (logIn(student)!= null)
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        public bool openEmailService(Student stu, string txtMail)
        {
            return accountService.updateEmail(stu, txtMail);
        }



       
        public SysAdmin adminLogin(SysAdmin admin)
        {
            return accountService.validateAdmin(admin.LoginId, admin.LoginPwd);
        }




        public DataTable getStudents()
        {
            return accountService.getStudentTable();
        }

        public bool addNewStudent(Student student)
        {
            return accountService.insertStudent(student);
        }

        #region
        public bool getAuthority(int roleId, String authName)
        {
            return accountService.selectAuthority(roleId, authName);
        }
        public DataSet getAuthorityDS()
        {
            return accountService.selectAuthorityDS();
        }
        public bool deletRole(int roleId)
        {
            return accountService.deleteRole(roleId);
        }
        public List<bool> getRoleInfor(string roleName)
        {
            return accountService.selectRoleInfor(roleName);
        }
        public bool updateRoleInfor(List<bool> authoritySet, String roleName)
        {
            return accountService.updateRoleAuthority(authoritySet, roleName);
        }
        public bool genneRoleInfor(List<bool> authoritys, String roleName)
        {
            return accountService.insertRole(authoritys, roleName);
        }
        #endregion
        #region
        public DataSet getOperatorDs()
        {
            return accountService.selectOperatorDataSet();
        }
        public bool addOperator(Operator oper)
        {
            return accountService.addOperator(oper);
        }
        public bool deletOperator(int id)
        {
            return accountService.deleteOperator(id);
        }
        public Operator selectOperatorInfor(int operatorId)
        {
            return accountService.selectOperator(operatorId);
        }
        public bool updataOperator(int operatorId, Operator oper)
        {
            return accountService.updateOperator(operatorId, oper);
        }
        #endregion
    }
}
